<extend name="Common@Base/layout"/>
<block name="body">
    <div class="home-main">
        <div class="container-fluid">
            <div class="row employee-top">
                <div class="col-sm-6">
                    <include file="Home/Public/directorpanel"/>
                </div>
                <!--<div class="col-sm-6">-->
                <!--<div class="panel panel-default panel-home-message">-->
                <!--<div class="panel-body">-->
                <!--<h4 class="home-title">审核通知</h4>-->
                <!--<div class="row row-wide">-->
                <!--<table class="table table-message-list">-->
                <!--<tbody>-->
                <!--<tr>-->
                <!--<td class="col-sm-6"><a href="#"><span class="text-lg text-muted">0</span> 减免申请中</a></td>-->
                <!--<td class="col-sm-6"><a href="#"><span class="text-lg text-important">1</span> 新减免结果</a></td>-->
                <!--</tr>-->
                <!--<tr>-->
                <!--<td><a href="#"><span class="text-lg text-muted">0</span> 协催申请中</a></td>-->
                <!--<td><a href="#"><span class="text-lg text-muted">0</span> 新协催结果</a></td>-->
                <!--</tr>-->
                <!--<tr>-->
                <!--<td><a href="#"><span class="text-lg text-important">10</span> 外访审核中</a></td>-->
                <!--<td><a href="#"><span class="text-lg text-important">1</span> 新外访审核结果</a></td>-->
                <!--</tr>-->
                <!--<tr>-->
                <!--<td><a href="#"><span class="text-lg text-important">1</span> 新外访排程</a></td>-->
                <!--<td></td>-->
                <!--</tr>-->
                <!--</tbody>-->
                <!--</table>-->
                <!--</div>-->
                <!--</div>-->
                <!--</div>-->
                <!--</div>-->
                <div class="col-sm-6">
                    <include file="Home/Public/notice"/>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-2">
                    <include file="Home/Public/orgtree"/>
                </div>
                <div class="col-sm-10">
                    <div class="panel panel-default panel-home-table">
                        <div class="panel-body">
                            <h4 class="home-title">部门业绩 (<?php echo date('Y年m月', time()); ?>) </h4>
                        </div>
                        <div class="table-responsive">
                            <table class="table table-bordered table-hover table-end">
                                <thead>
                                <tr>
                                    <th>名称</th>
                                    <th class="text-right">电话量</th>
                                    <th class="text-right">跟进客户数</th>
                                    <th class="text-right">签约客户数</th>
                                    <th class="text-right">新增客户数</th>
                                </tr>
                                </thead>
                                <tbody id="sum_table_tb">
                                <!--<tr style="font-weight: 800">-->
                                <!--<td><?php echo $depart['name']?></td>-->
                                <!--<td class="text-right">{$sum_depart_count.sum_follow_count}</td>-->
                                <!--<td class="text-right">{$sum_depart_count.sum_signed_count}</td>-->
                                <!--<td class="text-right">{$sum_depart_count.sum_add_count}</td>-->
                                <!--<td class="text-right">{$sum_depart_count.sum_phone_count}</td>-->
                                <!--</tr>-->
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>
    <script src="__PUBLIC__/Common/js/jquery.imagescroll.js"></script>
    <script>
        var allOrgTree = eval('{$org_json}');
        var tr_temp = $('<tr></tr>');
        var $tr = $(tr_temp);
        var td_temp = $('<td  class="text-right"></td>');
        var $td = $(td_temp);
        $(document).ready(function () {
            $('#org_depart_tree').delegate('.item-folder', 'click', function (e) {
                var $this = $(this);
                var nodeid = $this.find('.name').data('id');
                var wrapper = $('#sum_table_tb');
                wrapper.children().remove();
                var root = null;
                for (var index in allOrgTree) {
                    var tnode = allOrgTree[index];
                    root = searchNode(tnode, nodeid);
                    if (root != null) {
                        addRow(root, wrapper, 1);
                        break;
                    }
                }
            });

        })

        function searchNode(node, nodeid) {
            if (node['id'] == nodeid) {
                return node;
            } else {
                if (node['_child'] != null) {
                    for (var index in node['_child']) {
                        var child = node['_child'][index];
                        var r = searchNode(child, nodeid);
                        if (r != null) {
                            return r;
                        }
                    }
                }
            }
            return null;
        }

        function addRow(node, wrapper, i) {
            var level_class_name1 = 'level' + i;
            if (node != null) {
                var titletr = $tr.clone().addClass('td-title');

                titletr.append($td.clone().removeClass('text-right').addClass(level_class_name1).text(node.name));
                wrapper.append(titletr);

                var arr = new Array();
                arr[0] = 0;
                arr[1] = 0;
                arr[2] = 0;
                arr[3] = 0;
                if (node['sys_user'] != null) {
                    var level_class_name2 = 'level' + (i + 1);
                    for (var index in node['sys_user']) {
                        var leaf = node['sys_user'][index];
                        if (leaf.role < 3) {
                            var ctr = $tr.clone();
                            ctr.append($td.clone().removeClass('text-right').addClass(level_class_name2).text(leaf.name));
                            ctr.append($td.clone().text(leaf.phone_count));
                            ctr.append($td.clone().text(leaf.follow_count));
                            ctr.append($td.clone().text(leaf.signed_count));
                            ctr.append($td.clone().text(leaf.add_count));
                            wrapper.append(ctr);
                            arr[0] += parseInt(leaf.phone_count);
                            arr[1] += parseInt(leaf.follow_count);
                            arr[2] += parseInt(leaf.signed_count);
                            arr[3] += parseInt(leaf.add_count);
                        }
                    }
                }

                if (node['_child'] != null) {
                    for (var index in node['_child']) {
                        var child = node['_child'][index];
                        var re = addRow(child, wrapper, i + 1);
                        if (re != null) {
                            arr[0] += re[0];
                            arr[1] += re[1];
                            arr[2] += re[2];
                            arr[3] += re[3];
                        }
                    }
                }

                titletr.append($td.clone().text(arr[0]));
                titletr.append($td.clone().text(arr[1]));
                titletr.append($td.clone().text(arr[2]));
                titletr.append($td.clone().text(arr[3]));
                return arr;
            }
            return null;
        }
    </script>
    <include file="Home/Public/script"/>
</block>